//
//  ViewController.m
//  Segmented Test
//
//  Created by iD Student on 7/9/13.
//  Copyright (c) 2013 jasonkurtzman. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"bleep" withExtension:@"mp3"];
    NSError *error;
    bleepSound = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    if(error != nil)
    {
        NSLog(@"Bleep not loaded");
    }else{
        [bleepSound prepareToPlay];
    }
    
}

-(IBAction)segmentedAction:(id)sender
{
    UISegmentedControl *segmentButton = (UISegmentedControl*)sender;
    if(segmentButton.selectedSegmentIndex == 0)
    {
        //First Segment Button is selected
        label.text = @"ONE!";
    }else if(segmentButton.selectedSegmentIndex == 1)
    {
        //Second Segment Button
        label.text = @"TWO!";
    }else if(segmentButton.selectedSegmentIndex == 2)
    {
        //ViewController *vc = [[ViewController alloc]init];
        [self createAlert];
        [bleepSound play];
    }else if(segmentButton.selectedSegmentIndex == 3)
    {
        [bleepSound play];
    }
}

-(void) createAlert
{
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Alert Triggered" delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
    [alert show];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
